package cn.edu.ctbu.dp2.aop;

import cn.edu.ctbu.dp2.constant.REnum;
import cn.edu.ctbu.dp2.exception.RException;
import cn.edu.ctbu.dp2.util.RUtil;
import cn.edu.ctbu.dp2.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value = Exception.class)
    public R handleException(Exception e){
        if(e instanceof RException){
            RException rException =(RException)e;
            return RUtil.error(rException.getCode(),rException.getMessage());
        }
        return RUtil.error(REnum.UNKNOW_ERR);
    }

}
